package practice;

import java.util.Random;
import java.util.Stack;

/**
 * @author songZiHao
 * @version 1.0.0
 * @ClassName MinStack.java
 * @Description TODO
 * @createTime 2021年01月22日 17:39:00
 */
public class MinStack {
	private static final int CAPACITY = 1000_000_000;

	public static void main(String[] args){

		long startTime = System.currentTimeMillis();
		getRankNumber();
		long endTime = System.currentTimeMillis();

		System.out.println("\n数据排序总耗时："+(endTime-startTime));

	}

	static void getRankNumber(){

		byte[] dataByte = new byte[1<<16];

//         System.out.print("需排序的数:");
		for(int i=0;i<CAPACITY;i++){
			Random random = new Random();

			int k = random.nextInt(10000);

//             System.out.print(k+"\t");

			k = k+(1<<15);

			setBit(k,dataByte);

		}

		outPutBytes(dataByte);
	}


	static void setBit(int number,byte[] dataByte){


		int byteIndex = number/8;

		if(dataByte[byteIndex]==0){
			dataByte[byteIndex] = 0;
		}

		int innerIndex = number%8;

		dataByte[byteIndex] = (byte)(dataByte[byteIndex]|(1<<innerIndex));

	}


	static void outPutBytes(byte[] dataBytes){

		int count = 0;
		System.out.println();
		for(int i=0;i<dataBytes.length;i++){

			for(int j=0;j<8;j++){

				if((dataBytes[i]&(1<<j))!=0){
					count++;

					int number = i*8+j-(1<<15);
					System.out.print("第"+count+"个数: "+number+"\t");
				}
			}
		}

	}
	public static Stack<Integer> a=new Stack<Integer>(),b=new Stack<Integer>();

	public static void put(Integer val){
		a.add(val);
		if (b.isEmpty()||b.peek()>=val){
			b.add(val);
		}
	}
	public static void pop() {
		if (a.pop().equals(b.peek())){
			b.pop();
		}
	}
	public static int top() {
		return a.peek();
	}
	public static int min() {
		return b.peek();
	}

}
